home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / glass / glass.lha / GLASS / tm / tmgram.c < prev    next >
C/C++ Source or Header  |  1991-02-14  |  19KB  |  799 lines

  1.  
  2. # line 2 "tmgram.y"
  3. /* file: tmgram.y
  4.    A YACC grammar for Miranda algebraic datatypes
  5.  */
  6.  
  7. #include "tmdefs.h"
  8. #include <ctype.h>
  9. #include <tmc.h>
  10.  
  11. #include "tmds.h"
  12. #include "tmstring.h"
  13. #include "debug.h"
  14. #include "tmerror.h"
  15. #include "tmglobal.h"
  16. #include "tmlex.h"
  17. #include "tmmisc.h"
  18.  
  19. extern void setlexfile();
  20.  
  21. #define YYDEBUG 1   /* allow compilation of debugging code */
  22.  
  23. ds_list ans;
  24.  
  25.  
  26. # line 26 "tmgram.y"
  27. typedef union  {
  28.     ds pards;
  29.     ds_list pardslist;
  30.     constructor parcons;
  31.     constructor_list parconslist;
  32.     field parfield;
  33.     field_list parfieldlist;
  34.     char *parstring;
  35. } YYSTYPE;
  36. # define BAR 257
  37. # define COLCOLEQ 258
  38. # define EQEQ 259
  39. # define COLON 260
  40. # define COMMA 261
  41. # define NAME 262
  42. # define SEMI 263
  43. # define LSBRAC 264
  44. # define RSBRAC 265
  45. # define LRBRAC 266
  46. # define RRBRAC 267
  47. #define yyclearin yychar = -1
  48. #define yyerrok yyerrflag = 0
  49. extern int yychar;
  50. extern int yyerrflag;
  51. #ifndef YYMAXDEPTH
  52. #define YYMAXDEPTH 150
  53. #endif
  54. YYSTYPE yylval, yyval;
  55. typedef int yytabelem;
  56. # define YYERRCODE 256
  57.  
  58. # line 141 "tmgram.y"
  59.  
  60.  
  61. static void yyerror( s )
  62.  char *s;
  63. {
  64.     s = s; /* to stop complaints about unused arguments */
  65.     (void) sprintf( errpos, "%s(%d)", dsfilename, dslineno );
  66.     error( SYNTAXERR );
  67. }
  68.  
  69. /* Check a name on underscores and give an error message if one is found */
  70. static void ckunderscore( s )
  71.  char *s;
  72. {
  73.     if( index( s, '_' ) != NULL ){
  74.     (void) sprintf( errpos, "%s(%d)", dsfilename, dslineno );
  75.     (void) strcpy( errarg, s );
  76.     error( NOUNDERSCORE );
  77.     }
  78. }
  79.  
  80. /* Ensure that name 's' is a proper constructor name. */
  81. static void ckconsname( s )
  82.  char *s;
  83. {
  84.     if( s[0] == '\0' ) return;
  85.     ckunderscore( s );
  86.     if( !isupper( s[0] ) ){
  87.     (void) sprintf( errpos, "%s(%d)", dsfilename, dslineno );
  88.     (void) strcpy( errarg, s );
  89.     error( BADCONSNM );
  90.     }
  91. }
  92.  
  93. /* Ensure that name 's' is a proper type name. */
  94. static void cktypename( s )
  95.  char *s;
  96. {
  97.     if( s[0] == '\0' ) return;
  98.     ckunderscore( s );
  99.     if( !islower( s[0] ) ){
  100.     (void) sprintf( errpos, "%s(%d)", dsfilename, dslineno );
  101.     (void) strcpy( errarg, s );
  102.     error( BADTYPENM );
  103.     }
  104. }
  105.  
  106. /* Ensure that name 's' is a proper element name. */
  107. static void ckelmname( s )
  108.  char *s;
  109. {
  110.     if( s[0] == '\0' ) return;
  111.     ckunderscore( s );
  112. }
  113.  
  114. /* Ensure that there are no double names in tuple with name 'nm'
  115.  * and fields 'fields'.
  116.  */
  117. static void cktuple( nm, fields )
  118.  string nm;
  119.  field_list fields;
  120. {
  121.     register unsigned int ix;    /* index of currently checked field */
  122.     register unsigned int iy;    /* index of searched subsequent fields */
  123.     field fx;            /* checked field */
  124.     field fy;            /* searched field */
  125.     string fnm;            /* name of currently checked field */
  126.  
  127.     for( ix=0; ix<fields->sz; ix++ ){
  128.     fx = fields->arr[ix];
  129.     fnm = fx->sename;
  130.     iy = ix+1;
  131.     for( iy=ix+1; iy<fields->sz; iy++ ){
  132.         fy = fields->arr[iy];
  133.         if( strcmp( fy->sename, fnm ) == 0 ){
  134.         (void) sprintf( errpos, "in type '%s'", nm );
  135.         (void) sprintf( errarg, "'%s'", fnm );
  136.         error( DOUBLEFIELD );
  137.         }
  138.     }
  139.     }
  140. }
  141.  
  142. /* Ensure that there are no double names in each of the constructors of
  143.  * constructor type with name 'nm' and constructors 'cons'.
  144.  */
  145. static void ckconstructor( nm, cons )
  146.  string nm;
  147.  constructor_list cons;
  148. {
  149.     constructor conx;
  150.     constructor cony;
  151.     field_list fields;
  152.     register unsigned int cix;    /* index in constructor list */
  153.     register unsigned int ix;    /* index of currently checked field */
  154.     register unsigned int six;    /* index for searching of fields/constr. */
  155.     field fx;            /* checked field */
  156.     field fy;            /* searched field */
  157.     string fnm;            /* name of currently checked field */
  158.     string connm;        /* name of current constructor */
  159.  
  160.     for( cix=0; cix<cons->sz; cix++ ){
  161.     conx = cons->arr[cix];
  162.     fields = conx->confields;
  163.     connm = conx->conname;
  164.     for( six=cix+1; six<cons->sz; six++ ){
  165.         cony = cons->arr[six];
  166.         if( strcmp( cony->conname, connm ) == 0 ){
  167.         (void) sprintf( errpos, "in type '%s'", nm );
  168.         (void) sprintf( errarg, "'%s'", connm );
  169.         error( DOUBLECONS );
  170.         }
  171.     }
  172.     for( ix=0; ix<fields->sz; ix++ ){
  173.         fx = fields->arr[ix];
  174.         fnm = fx->sename;
  175.         six = ix+1;
  176.         for( six=ix+1; six<fields->sz; six++ ){
  177.         fy = fields->arr[six];
  178.         if( strcmp( fy->sename, fnm ) == 0 ){
  179.             (void) sprintf(
  180.             errpos,
  181.             "in type '%s', constructor '%s'",
  182.             nm,
  183.             connm
  184.             );
  185.             (void) sprintf( errarg, "'%s'", fnm );
  186.             error( DOUBLEFIELD );
  187.         }
  188.         }
  189.     }
  190.     }
  191. }
  192.  
  193. /* top level of parser. */
  194. ds_list parse( f )
  195.  FILE *f;
  196. {
  197.     setlexfile( f );
  198.     (void) yyparse();
  199.     return( ans );
  200. }
  201. yytabelem yyexca[] ={
  202. -1, 1,
  203.     0, -1,
  204.     -2, 0,
  205. -1, 2,
  206.     0, 1,
  207.     -2, 0,
  208.     };
  209. # define YYNPROD 19
  210. # define YYLAST 45
  211. yytabelem yyact[]={
  212.  
  213.     25,    14,    32,    29,    16,    30,    24,    27,     9,     5,
  214.     15,    31,    21,    13,    26,     6,     7,     8,    19,    20,
  215.     11,    12,     4,    17,    18,    10,     3,     2,     1,     0,
  216.      0,     0,     0,     0,     0,     0,    23,    22,     0,     0,
  217.      0,     0,     0,     0,    28 };
  218. yytabelem yypact[]={
  219.  
  220.  -1000, -1000,  -247, -1000,  -242,  -255, -1000,  -249,  -265, -1000,
  221.   -253, -1000, -1000, -1000,  -250, -1000,  -249,  -250,  -261, -1000,
  222.   -246, -1000, -1000, -1000,  -256,  -250,  -259, -1000, -1000, -1000,
  223.   -251,  -263, -1000 };
  224. yytabelem yypgo[]={
  225.  
  226.      0,    28,    27,    26,    25,    20,    24,    23,    18,    22,
  227.     21,    19 };
  228. yytabelem yyr1[]={
  229.  
  230.      0,     1,     2,     2,     3,     3,     3,     6,     6,     4,
  231.      4,     5,     7,     7,     8,     8,     9,    10,    11 };
  232. yytabelem yyr2[]={
  233.  
  234.      0,     3,     1,     5,     9,    13,     5,     3,     7,     3,
  235.      7,     5,     1,     5,     7,    11,     3,     3,     3 };
  236. yytabelem yychk[]={
  237.  
  238.  -1000,    -1,    -2,    -3,    -9,   256,   262,   258,   259,   263,
  239.     -4,    -5,   -10,   262,   266,   263,   257,    -7,    -6,    -8,
  240.    -11,   262,    -5,    -8,   267,   261,   260,   263,    -8,   262,
  241.    264,   262,   265 };
  242. yytabelem yydef[]={
  243.  
  244.      2,    -2,    -2,     3,     0,     0,    16,     0,     0,     6,
  245.      0,     9,    12,    17,     0,     4,     0,    11,     0,     7,
  246.      0,    18,    10,    13,     0,     0,     0,     5,     8,    14,
  247.      0,     0,    15 };
  248. typedef struct { char *t_name; int t_val; } yytoktype;
  249. #ifndef YYDEBUG
  250. #    define YYDEBUG    0    /* don't allow debugging */
  251. #endif
  252.  
  253. #if YYDEBUG
  254.  
  255. yytoktype yytoks[] =
  256. {
  257.     "BAR",    257,
  258.     "COLCOLEQ",    258,
  259.     "EQEQ",    259,
  260.     "COLON",    260,
  261.     "COMMA",    261,
  262.     "NAME",    262,
  263.     "SEMI",    263,
  264.     "LSBRAC",    264,
  265.     "RSBRAC",    265,
  266.     "LRBRAC",    266,
  267.     "RRBRAC",    267,
  268.     "-unknown-",    -1    /* ends search */
  269. };
  270.  
  271. char * yyreds[] =
  272. {
  273.     "-no such reduction-",
  274.     "top : typelist",
  275.     "typelist : /* empty */",
  276.     "typelist : typelist type",
  277.     "type : typename COLCOLEQ constructorlist SEMI",
  278.     "type : typename EQEQ LRBRAC tuplebody RRBRAC SEMI",
  279.     "type : error SEMI",
  280.     "tuplebody : field",
  281.     "tuplebody : tuplebody COMMA field",
  282.     "constructorlist : constructor",
  283.     "constructorlist : constructorlist BAR constructor",
  284.     "constructor : consname fieldlist",
  285.     "fieldlist : /* empty */",
  286.     "fieldlist : fieldlist field",
  287.     "field : elmname COLON NAME",
  288.     "field : elmname COLON LSBRAC NAME RSBRAC",
  289.     "typename : NAME",
  290.     "consname : NAME",
  291.     "elmname : NAME",
  292. };
  293. #endif /* YYDEBUG */
  294.     /**********************************************************
  295.      * Copyright (C) Data General Corporation, 1984 - 1988      *
  296.      * All Rights Reserved.                      *
  297.      * Licensed Material-Property of Data General Corporation. *
  298.      **********************************************************/
  299.         /**************************************************
  300.          * This software is made available solely pursuant *
  301.         * to the terms of a DGC license              *
  302.          * agreement which governs its use.              *
  303.          **************************************************/
  304.  
  305. /*    $What: <@(#) yaccpar.c,v    2.1.1.1> $    */
  306.  
  307. /* #ident    "@(#)yacc:yaccpar    1.10" */
  308.  
  309. /*
  310. ** Skeleton parser driver for yacc output
  311. */
  312.  
  313. /*
  314. ** yacc user known macros and defines
  315. */
  316. #define YYERROR        goto yyerrlab
  317. #define YYACCEPT    return(0)
  318. #define YYABORT        return(1)
  319. #define YYBACKUP( newtoken, newvalue )\
  320. {\
  321.     if ( yychar >= 0 || ( yyr2[ yytmp ] >> 1 ) != 1 )\
  322.     {\
  323.         yyerror( "syntax error - cannot backup" );\
  324.         goto yyerrlab;\
  325.     }\
  326.     yychar = newtoken;\
  327.     yystate = *yyps;\
  328.     yylval = newvalue;\
  329.     goto yynewstate;\
  330. }
  331. #define YYRECOVERING()    (!!yyerrflag)
  332. #ifndef YYDEBUG
  333. #    define YYDEBUG    1    /* make debugging available */
  334. #endif    /*  #ifndef YYDEBUG  */
  335.  
  336. /*
  337. ** user known globals
  338. */
  339. int yydebug;            /* set to 1 to get debugging */
  340.  
  341. /*
  342. ** driver internal defines
  343. */
  344. #define YYFLAG        (-1000)
  345.  
  346. /*
  347. ** global variables used by the parser
  348. */
  349. YYSTYPE yyv[ YYMAXDEPTH ];    /* value stack */
  350. int yys[ YYMAXDEPTH ];        /* state stack */
  351.  
  352. YYSTYPE *yypv;            /* top of value stack */
  353. int *yyps;            /* top of state stack */
  354.  
  355. int yystate;            /* current state */
  356. int yytmp;            /* extra var (lasts between blocks) */
  357.  
  358. int yynerrs;            /* number of errors */
  359. int yyerrflag;            /* error recovery flag */
  360. int yychar;            /* current input token number */
  361.  
  362.  
  363.  
  364. /*
  365. ** yyparse - return 0 if worked, 1 if syntax error not recovered from
  366. */
  367. int
  368. yyparse()
  369. {
  370.     register YYSTYPE *yypvt;    /* top of value stack for $vars */
  371.  
  372.     /*
  373.     ** Initialize externals - yyparse may be called more than once
  374.     */
  375.     yypv = &yyv[-1];
  376.     yyps = &yys[-1];
  377.     yystate = 0;
  378.     yytmp = 0;
  379.     yynerrs = 0;
  380.     yyerrflag = 0;
  381.     yychar = -1;
  382.  
  383.     goto yystack;
  384.     {
  385.         register YYSTYPE *yy_pv;    /* top of value stack */
  386.         register int *yy_ps;        /* top of state stack */
  387.         register int yy_state;        /* current state */
  388.         register int  yy_n;        /* internal state number info */
  389.  
  390.         /*
  391.         ** get globals into registers.
  392.         ** branch to here only if YYBACKUP was called.
  393.         */
  394.     yynewstate:
  395.         yy_pv = yypv;
  396.         yy_ps = yyps;
  397.         yy_state = yystate;
  398.         goto yy_newstate;
  399.  
  400.         /*
  401.         ** get globals into registers.
  402.         ** either we just started, or we just finished a reduction
  403.         */
  404.     yystack:
  405.         yy_pv = yypv;
  406.         yy_ps = yyps;
  407.         yy_state = yystate;
  408.  
  409.         /*
  410.         ** top of for (;;) loop while no reductions done
  411.         */
  412.     yy_stack:
  413.         /*
  414.         ** put a state and value onto the stacks
  415.         */
  416. #if    YYDEBUG
  417.         /*
  418.         ** if debugging, look up token value in list of value vs.
  419.         ** name pairs.  0 and negative (-1) are special values.
  420.         ** Note: linear search is used since time is not a real
  421.         ** consideration while debugging.
  422.         */
  423.         if ( yydebug )
  424.         {
  425.             register int yy_i;
  426.  
  427.             printf( "State %d, token ", yy_state );
  428.             if ( yychar == 0 )
  429.                 printf( "end-of-file\n" );
  430.             else if ( yychar < 0 )
  431.                 printf( "-none-\n" );
  432.             else
  433.             {
  434.                 for ( yy_i = 0; yytoks[yy_i].t_val >= 0;
  435.                     yy_i++ )
  436.                 {
  437.                     if ( yytoks[yy_i].t_val == yychar )
  438.                         break;
  439.                 }
  440.                 printf( "%s\n", yytoks[yy_i].t_name );
  441.             }
  442.         }
  443. #endif    /*  #if    YYDEBUG  */
  444.         if ( ++yy_ps >= &yys[ YYMAXDEPTH ] )    /* room on stack? */
  445.         {
  446.             yyerror( "yacc stack overflow" );
  447.             YYABORT;
  448.         }
  449.         *yy_ps = yy_state;
  450.         *++yy_pv = yyval;
  451.  
  452.         /*
  453.         ** we have a new state - find out what to do
  454.         */
  455.     yy_newstate:
  456.         if ( ( yy_n = yypact[ yy_state ] ) <= YYFLAG )
  457.             goto yydefault;        /* simple state */
  458. #if    YYDEBUG
  459.         /*
  460.         ** if debugging, need to mark whether new token grabbed
  461.         */
  462.         yytmp = yychar < 0;
  463. #endif    /*  #if    YYDEBUG  */
  464.         if ( ( yychar < 0 ) && ( ( yychar = yylex() ) < 0 ) )
  465.             yychar = 0;        /* reached EOF */
  466. #if    YYDEBUG
  467.         if ( yydebug && yytmp )
  468.         {
  469.             register int yy_i;
  470.  
  471.             printf( "Received token " );
  472.             if ( yychar == 0 )
  473.                 printf( "end-of-file\n" );
  474.             else if ( yychar < 0 )
  475.                 printf( "-none-\n" );
  476.             else
  477.             {
  478.                 for ( yy_i = 0; yytoks[yy_i].t_val >= 0;
  479.                     yy_i++ )
  480.                 {
  481.                     if ( yytoks[yy_i].t_val == yychar )
  482.                         break;
  483.                 }
  484.                 printf( "%s\n", yytoks[yy_i].t_name );
  485.             }
  486.         }
  487. #endif    /*  #if    YYDEBUG  */
  488.         if ( ( ( yy_n += yychar ) < 0 ) || ( yy_n >= YYLAST ) )
  489.             goto yydefault;
  490.         if ( yychk[ yy_n = yyact[ yy_n ] ] == yychar )    /*valid shift*/
  491.         {
  492.             yychar = -1;
  493.             yyval = yylval;
  494.             yy_state = yy_n;
  495.             if ( yyerrflag > 0 )
  496.                 yyerrflag--;
  497.             goto yy_stack;
  498.         }
  499.  
  500.     yydefault:
  501.         if ( ( yy_n = yydef[ yy_state ] ) == -2 )
  502.         {
  503. #if    YYDEBUG
  504.             yytmp = yychar < 0;
  505. #endif    /*  #if    YYDEBUG  */
  506.             if ( ( yychar < 0 ) && ( ( yychar = yylex() ) < 0 ) )
  507.                 yychar = 0;        /* reached EOF */
  508. #if    YYDEBUG
  509.             if ( yydebug && yytmp )
  510.             {
  511.                 register int yy_i;
  512.  
  513.                 printf( "Received token " );
  514.                 if ( yychar == 0 )
  515.                     printf( "end-of-file\n" );
  516.                 else if ( yychar < 0 )
  517.                     printf( "-none-\n" );
  518.                 else
  519.                 {
  520.                     for ( yy_i = 0;
  521.                         yytoks[yy_i].t_val >= 0;
  522.                         yy_i++ )
  523.                     {
  524.                         if ( yytoks[yy_i].t_val
  525.                             == yychar )
  526.                         {
  527.                             break;
  528.                         }
  529.                     }
  530.                     printf( "%s\n", yytoks[yy_i].t_name );
  531.                 }
  532.             }
  533. #endif    /*  #if    YYDEBUG  */
  534.             /*
  535.             ** look through exception table
  536.             */
  537.             {
  538.                 register int *yyxi = yyexca;
  539.  
  540.                 while ( ( *yyxi != -1 ) ||
  541.                     ( yyxi[1] != yy_state ) )
  542.                 {
  543.                     yyxi += 2;
  544.                 }
  545.                 while ( ( *(yyxi += 2) >= 0 ) &&
  546.                     ( *yyxi != yychar ) )
  547.                     ;
  548.                 if ( ( yy_n = yyxi[1] ) < 0 )
  549.                     YYACCEPT;
  550.             }
  551.         }
  552.  
  553.         /*
  554.         ** check for syntax error
  555.         */
  556.         if ( yy_n == 0 )    /* have an error */
  557.         {
  558.             /* no worry about speed here! */
  559.             switch ( yyerrflag )
  560.             {
  561.             case 0:        /* new error */
  562.                 yyerror( "syntax error" );
  563.                 goto skip_init;
  564.             yyerrlab:
  565.                 /*
  566.                 ** get globals into registers.
  567.                 ** we have a user generated syntax type error
  568.                 */
  569.                 yy_pv = yypv;
  570.                 yy_ps = yyps;
  571.                 yy_state = yystate;
  572.                 yynerrs++;
  573.             skip_init:
  574.             case 1:
  575.             case 2:        /* incompletely recovered error */
  576.                     /* try again... */
  577.                 yyerrflag = 3;
  578.                 /*
  579.                 ** find state where "error" is a legal
  580.                 ** shift action
  581.                 */
  582.                 while ( yy_ps >= yys )
  583.                 {
  584.                     yy_n = yypact[ *yy_ps ] + YYERRCODE;
  585.                     if ( yy_n >= 0 && yy_n < YYLAST &&
  586.                         yychk[yyact[yy_n]] == YYERRCODE)                    {
  587.                         /*
  588.                         ** simulate shift of "error"
  589.                         */
  590.                         yy_state = yyact[ yy_n ];
  591.                         goto yy_stack;
  592.                     }
  593.                     /*
  594.                     ** current state has no shift on
  595.                     ** "error", pop stack
  596.                     */
  597. #if    YYDEBUG
  598. #    define _POP_ "Error recovery pops state %d, uncovers state %d\n"
  599.                     if ( yydebug )
  600.                         printf( _POP_, *yy_ps,
  601.                             yy_ps[-1] );
  602. #    undef _POP_
  603. #endif    /*  #if    YYDEBUG  */
  604.                     yy_ps--;
  605.                     yy_pv--;
  606.                 }
  607.                 /*
  608.                 ** there is no state on stack with "error" as
  609.                 ** a valid shift.  give up.
  610.                 */
  611.                 YYABORT;
  612.             case 3:        /* no shift yet; eat a token */
  613. #if    YYDEBUG
  614.                 /*
  615.                 ** if debugging, look up token in list of
  616.                 ** pairs.  0 and negative shouldn't occur,
  617.                 ** but since timing doesn't matter when
  618.                 ** debugging, it doesn't hurt to leave the
  619.                 ** tests here.
  620.                 */
  621.                 if ( yydebug )
  622.                 {
  623.                     register int yy_i;
  624.  
  625.                     printf( "Error recovery discards " );
  626.                     if ( yychar == 0 )
  627.                         printf( "token end-of-file\n" );
  628.                     else if ( yychar < 0 )
  629.                         printf( "token -none-\n" );
  630.                     else
  631.                     {
  632.                         for ( yy_i = 0;
  633.                             yytoks[yy_i].t_val >= 0;
  634.                             yy_i++ )
  635.                         {
  636.                             if ( yytoks[yy_i].t_val
  637.                                 == yychar )
  638.                             {
  639.                                 break;
  640.                             }
  641.                         }
  642.                         printf( "token %s\n",
  643.                             yytoks[yy_i].t_name );
  644.                     }
  645.                 }
  646. #endif    /*  #if    YYDEBUG  */
  647.                 if ( yychar == 0 )    /* reached EOF. quit */
  648.                     YYABORT;
  649.                 yychar = -1;
  650.                 goto yy_newstate;
  651.             }
  652.         }/* end if ( yy_n == 0 ) */
  653.         /*
  654.         ** reduction by production yy_n
  655.         ** put stack tops, etc. so things right after switch
  656.         */
  657. #if    YYDEBUG
  658.         /*
  659.         ** if debugging, print the string that is the user's
  660.         ** specification of the reduction which is just about
  661.         ** to be done.
  662.         */
  663.         if ( yydebug )
  664.             printf( "Reduce by (%d) \"%s\"\n",
  665.                 yy_n, yyreds[ yy_n ] );
  666. #endif    /*  #if    YYDEBUG  */
  667.         yytmp = yy_n;            /* value to switch over */
  668.         yypvt = yy_pv;            /* $vars top of value stack */
  669.         /*
  670.         ** Look in goto table for next state
  671.         ** Sorry about using yy_state here as temporary
  672.         ** register variable, but why not, if it works...
  673.         ** If yyr2[ yy_n ] doesn't have the low order bit
  674.         ** set, then there is no action to be done for
  675.         ** this reduction.  So, no saving & unsaving of
  676.         ** registers done.  The only difference between the
  677.         ** code just after the if and the body of the if is
  678.         ** the goto yy_stack in the body.  This way the test
  679.         ** can be made before the choice of what to do is needed.
  680.         */
  681.         {
  682.             /* length of production doubled with extra bit */
  683.             register int yy_len = yyr2[ yy_n ];
  684.  
  685.             if ( !( yy_len & 01 ) )
  686.             {
  687.                 yy_len >>= 1;
  688.                 yyval = ( yy_pv -= yy_len )[1];    /* $$ = $1 */
  689.                 yy_state = yypgo[ yy_n = yyr1[ yy_n ] ] +
  690.                     *( yy_ps -= yy_len ) + 1;
  691.                 if ( yy_state >= YYLAST ||
  692.                     yychk[ yy_state =
  693.                     yyact[ yy_state ] ] != -yy_n )
  694.                 {
  695.                     yy_state = yyact[ yypgo[ yy_n ] ];
  696.                 }
  697.                 goto yy_stack;
  698.             }
  699.             yy_len >>= 1;
  700.             yyval = ( yy_pv -= yy_len )[1];    /* $$ = $1 */
  701.             yy_state = yypgo[ yy_n = yyr1[ yy_n ] ] +
  702.                 *( yy_ps -= yy_len ) + 1;
  703.             if ( yy_state >= YYLAST ||
  704.                 yychk[ yy_state = yyact[ yy_state ] ] != -yy_n )
  705.             {
  706.                 yy_state = yyact[ yypgo[ yy_n ] ];
  707.             }
  708.         }
  709.                     /* save until reenter driver code */
  710.         yystate = yy_state;
  711.         yyps = yy_ps;
  712.         yypv = yy_pv;
  713.     }
  714.     /*
  715.     ** code supplied by user is placed in this switch
  716.     */
  717.     switch( yytmp )
  718.     {
  719.         
  720. case 1:
  721. # line 62 "tmgram.y"
  722. { ans = yypvt[-0].pardslist;                          } break;
  723. case 2:
  724. # line 65 "tmgram.y"
  725. { yyval.pardslist = new_ds_list();                } break;
  726. case 3:
  727. # line 66 "tmgram.y"
  728. { app_ds_list( yypvt[-1].pardslist, yypvt[-0].pards ); yyval.pardslist = yypvt[-1].pardslist;    } break;
  729. case 4:
  730. # line 71 "tmgram.y"
  731. {
  732.         ckconstructor( yypvt[-3].parstring, yypvt[-1].parconslist );
  733.         yyval.pards = new_DsCons( yypvt[-3].parstring, yypvt[-1].parconslist );
  734.     } break;
  735. case 5:
  736. # line 76 "tmgram.y"
  737. {
  738.         cktuple( yypvt[-5].parstring, yypvt[-2].parfieldlist );
  739.         yyval.pards = new_DsTuple( yypvt[-5].parstring, yypvt[-2].parfieldlist );
  740.     } break;
  741. case 6:
  742. # line 81 "tmgram.y"
  743. {
  744.         yyval.pards = new_DsCons( new_string( "" ), new_constructor_list() );
  745.     } break;
  746. case 7:
  747. # line 88 "tmgram.y"
  748. {
  749.         yyval.parfieldlist = new_field_list();
  750.         app_field_list( yyval.parfieldlist, yypvt[-0].parfield );
  751.     } break;
  752. case 8:
  753. # line 93 "tmgram.y"
  754. {
  755.         app_field_list( yypvt[-2].parfieldlist, yypvt[-0].parfield );
  756.         yyval.parfieldlist = yypvt[-2].parfieldlist;
  757.     } break;
  758. case 9:
  759. # line 101 "tmgram.y"
  760. {
  761.           yyval.parconslist = new_constructor_list();
  762.           app_constructor_list( yyval.parconslist, yypvt[-0].parcons );
  763.       } break;
  764. case 10:
  765. # line 106 "tmgram.y"
  766. {
  767.           app_constructor_list(yypvt[-2].parconslist, yypvt[-0].parcons);
  768.           yyval.parconslist = yypvt[-2].parconslist;
  769.       } break;
  770. case 11:
  771. # line 114 "tmgram.y"
  772. {
  773.           yyval.parcons = new_constructor(yypvt[-1].parstring, yypvt[-0].parfieldlist);
  774.       } break;
  775. case 12:
  776. # line 120 "tmgram.y"
  777. { yyval.parfieldlist = new_field_list();            } break;
  778. case 13:
  779. # line 121 "tmgram.y"
  780. { app_field_list(yypvt[-1].parfieldlist, yypvt[-0].parfield); yyval.parfieldlist = yypvt[-1].parfieldlist;  } break;
  781. case 14:
  782. # line 125 "tmgram.y"
  783. { yyval.parfield = new_field( 0, yypvt[-2].parstring, yypvt[-0].parstring );       } break;
  784. case 15:
  785. # line 126 "tmgram.y"
  786. { yyval.parfield = new_field( 1, yypvt[-4].parstring, yypvt[-1].parstring );       } break;
  787. case 16:
  788. # line 130 "tmgram.y"
  789. { cktypename( yypvt[-0].parstring ); yyval.parstring = yypvt[-0].parstring;         } break;
  790. case 17:
  791. # line 134 "tmgram.y"
  792. { ckconsname( yypvt[-0].parstring ); yyval.parstring = yypvt[-0].parstring;         } break;
  793. case 18:
  794. # line 138 "tmgram.y"
  795. { ckelmname( yypvt[-0].parstring ); yyval.parstring = yypvt[-0].parstring;          } break;
  796.     }
  797.     goto yystack;        /* reset registers in driver code */
  798. }
  799.